package com.dateConstruction._04_seqStack;

import com.dateConstruction._02_seqList.SeqList;

public final class SeqStack<T> implements Stack<T> {

    // 使用顺序表存储栈元素
    private SeqList<T> list;

    // 构造容量为length的空栈
    public SeqStack(int length) {
        this.list = new SeqList<T>(length);
    }
    
    // 构造默认长度的空栈
    public SeqStack() {
        this(64);
    }
    
    // 判空
    public boolean isEmpty() {
        // TODO Auto-generated method stub
        return this.list.isEmpty();
    }

    // 将x存入栈中
    public void push(T x) {
        // TODO Auto-generated method stub
        this.list.insert(this.list.n, x);
    }

    // 获得栈顶元素
    public T peek() {
        // TODO Auto-generated method stub
        return this.list.get(list.size() - 1);
    }

    // 出栈，返回出栈元素
    public T pop() {
        // TODO Auto-generated method stub
        return this.list.remove(list.size() - 1);
    }
    
    // 返回字符串描述
    public String toString() {
        return this.list.toString();
    }
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        SeqStack<Integer> ss = new SeqStack<Integer>(0);
        ss.push(11);
        ss.push(22);
        ss.push(33);
        System.out.println(ss);
        
    }
}
